<?php

class Recover extends Model
{
	//creating variables username and password
	var $username = '';
	var $pw_rec_question = '';	
	var $pw_rec_answer = '';
	
	public function Recover()
	{
		// Call the model constructor
		parent::Model();
		
		$this->load->database();
	}
	
	public function check()
	{		
		//checking to see if information is there
		if(isset($_POST) && $_POST != NULL)
		{
			$errors = array();
		
			if(trim($_POST['username']) == '' || trim($_POST['pw_rec_answer']) == '')
			{
				$info['password'] = "Incorrect recovery.";
			}	
			else
			{
				mysql_connect('2006.ispace.ci.fsu.edu', 'rmv06d', 'zqgvht2m');
				mysql_select_db('runningrecords');
				
				$sql = "SELECT * FROM users WHERE username='" . $_POST['username'] . "'";
				$result = mysql_query($sql) or die(mysql_error());
				$pull = mysql_fetch_array($result) or die(mysql_error());
				
				if($pull['pw_rec_question'] == $_POST['pw_rec_question'] && $pull['pw_rec_answer'] == $_POST['pw_rec_answer'])
					$info['password'] = "Success!  Your password is: " . $pull['password'];
			}
			
			return $info;
			
		}
	}
}